<#import "/global.ftl" as user_list />
<@user_list.importEasyUi/>
<div>
    <span class="menu_icon_service"></span>
<@labelExt num=12>

</@labelExt>
</div>
<form id="userQueryForm">
    <table>
        <tr>
            <td><label for="LoginName">LoginName:</label></td>
            <td>
                <input class="easyui-validatebox" type="text" id="seqLoginName" name="loginName" value=""/>
            </td>
            <td><input type="button" value="Search" id="searchBtn" onclick="searchClick()" /></td><td>&nbsp;</td>
        </tr>
    </table>
</form>
<table id="userTables"  style="width:100%;height:400px"
</table>
<div id="addUserDiv" data-options="iconCls:'icon-save',resizable:true,modal:true"></div>
<script type="text/javascript">
    var total = "${pageInfo.total}";
    var pageSize = "${pageInfo.pageSize}";
    var pageType = "add";
    var pageName = "edit";
    var selectRow;

    function searchClick(){
        $("#userTables").datagrid('load',{"loginName":$('#seqLoginName').val()});
    }

    $(function(){
        $("#userTables").datagrid({
            url : '<@user_list.basePath/>/sys/user/list',
            method: 'post',
            pageSize : 10,
            pageList : [10, 20, 30, 40, 50],
            border : true,
            pagination:true,
            idField : 'accountId',
            rownumbers: true,
            singleSelect:true,
            fitColumns:true,
            loadMsg:'数据正在努力加载，请稍后...',
            columns : [[
                { field: 'accountId', title: 'accountId', width: 100},
                { field: 'loginName', title: 'loginName', width: 100},
                { field: 'userName', title: 'userName', width: 100},
                { field: 'realName', title: 'realName', width: 100},
                { field: 'status', title: 'status', width: 100}
            ]],
            toolbar: [
                { iconCls: 'icon-add',      handler: function(){ selectRow={"accountId":''};pageName = "edit"; pageType = "add"; editUser(); }}, '-',
                { iconCls: 'icon-edit',     handler: function(){
                    selectRow = $("#userTables").datagrid('getSelected');
                    console.log(selectRow);
                    if(selectRow==undefined){
                        $.messager.alert('Info','请选择要修改的行');
                        return ;
                    }
                    pageName = "edit";
                    pageType = "edit";
                    editUser();
                }}, '-',
                { iconCls: 'icon-cancel',   handler: function(){
                    $.messager.confirm('Confirm','Are you sure you want to delete record?',function(r){
                        if(r){
                            userDelete();
                        }
                    });
                }}, '-',
                { iconCls: 'icon-search',   handler: function(){
                    selectRow = $("#userTables").datagrid('getSelected');
                    console.log(selectRow);
                    if(selectRow==undefined){
                        $.messager.alert('Info','请选择要修改的行');
                        return ;
                    }
                    pageName = "view";
                    pageType = "view";
                    viewUser();
                }}

            ]
        });
    });

    function userDelete(){
        selectRow = $("#userTables").datagrid('getSelected');
        console.log(selectRow);
        if(selectRow==undefined){
            $.messager.alert('Info','请选择要删除的行');
            return ;
        }
        $.post('<@user_list.basePath/>/sys/user/delete',
                {"accountId": selectRow['accountId']},
                function(data){
                    if(true==data.success){
                        $.messager.alert('Info','删除成功!');
                        $("#userTables").datagrid('reload');
                    }
                });
    }

    function editUser(){
        $('#addUserDiv').dialog({
            title: 'User '+pageType,
            width: 400,
            height: 350,
            closed: false,
            cache: false,
            href: '<@user_list.basePath/>/sys/user/edit',
            queryParams: {"pageType":pageType,"accountId":selectRow['accountId'] },
            modal: true,
            iconCls:'icon-edit',
            buttons:[
                { text: 'Save', handler: function () { editSubmit(); }},
                { text: 'Close', handler: function () { $('#addUserDiv').dialog('close'); }}
            ]
        });
    }

    function viewUser() {
        $('#addUserDiv').dialog({
            title: 'User ' + pageType,
            width: 400,
            height: 350,
            closed: false,
            cache: false,
            href: '<@user_list.basePath/>/sys/user/view',
            queryParams: {"pageType": pageType, "accountId": selectRow['accountId']},
            modal: true,
            iconCls: 'icon-search',
            buttons: [
                { text: 'Close', handler: function () { $('#addUserDiv').dialog('close'); }}
            ]
        });
    }
</script>

